package gov.mogaha.ntis.cmm.mob.law.util;

import gov.mogaha.ntis.cmm.mob.util.Logger;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.content.res.AssetManager;
import android.util.Log;

public class CmmMobLawStrUtil {
	
	public static StringBuffer characters(char ch[], int start, int length) {
		StringBuffer sb = new StringBuffer();
		for (int i = start; i < start + length; i++) {
			switch (ch[i]) {
			case '\r':
				break;
			case '\t':
				break;
			case '\n':
				break;
			default:
				sb.append(ch[i]);
				break;
			}
		}
		return sb;
	}

	public static String Nvl(String src, String pre) {
		if (src != null) {
			return src;
		} else {
			return pre;
		}
	}
	
	public static String getAssetsFileContent(String fileName, AssetManager am){
		StringBuffer sb = new StringBuffer();
	
		try {
			InputStream is = am.open(fileName);
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String tmp=br.readLine();
			while(tmp!=null){
				sb.append((tmp+"\n"));
				tmp=br.readLine();
			}
		} catch (IOException e) {
			Logger.e("StrUtil getAssetsFileContent Error");
		}
		
		
		
		return sb.toString();
	}
	
	public static String getHtmlStartWithCSS(String[] files){
		StringBuffer sb = new StringBuffer();
		
		sb.append(CmmMobLawStr._HTML_START_TAG);
		
		for(String file : files){
			sb.append(String.format(CmmMobLawStr._CSS_TAG, file));
		}
				
		
		return sb.toString();
	}
	
}
